//package com.ssm.springboot.config;
//
//
//import com.ssm.springboot.dao.TbPermissionDao;
//import com.ssm.springboot.pojo.TbPermission;
//import com.ssm.springboot.pojo.TbUser;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import org.springframework.stereotype.Service;
//import org.springframework.web.servlet.HandlerInterceptor;
//
//import javax.annotation.PostConstruct;
//import javax.annotation.Resource;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.util.HashSet;
//import java.util.List;
//@Component
//public class MyInterceptor implements HandlerInterceptor {
//    @Autowired
//    private TbPermissionDao tbPermissionDao;
//
//
//
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        TbUser user = (TbUser) request.getSession().getAttribute("user");
//        if (user != null) {
//            Integer id = user.getId();
//            List<TbPermission> permissions = tbPermissionDao.findPermissionByUserid(id);
//            HashSet<String> permissionName = new HashSet<>();
//            for (TbPermission p : permissions) {
//                permissionName.add(p.getPermissionName());
//            }
//            String requestURI = request.getRequestURI();
//            if (!permissionName.contains(requestURI)) {
//                return false;
//            } else {
//                return true;
//            }
//        }else {
//            response.sendRedirect("/layuimini-master/login.html");
//            return false;
//        }
//    }
//}
